package com.muki.contentSeen;

import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

@Component
public class ContentSeenServer {

	private final Logger log = Logger.getLogger("data");
	private ContentPersistant contentPersistant;
	
	@Autowired
	public void setContentSeenServer(ContentPersistant contentPersistant) {
		this.contentPersistant = contentPersistant;
	}
	/**
	 * 绑定队列content-seen
	 * 接收消息
	 * @param map
	 */
	@JmsListener(destination="content-seen")
	public void receive(Map<String,String> map) {
		String topic = (String) map.get("topic");
		int depth = Integer.valueOf(map.get("depth"));
		String url = (String) map.get("url");
		String content = (String) map.get("content");
		log.info("receive data { "+topic+" | "+depth+" | "+url+" | "+content.length()+" }");
		Content c = ContentFactory.receive(topic, depth, url, content);
		ContentFactory.save(contentPersistant, c);
	}
}
